#       In The Mood - Rhythmbox predictive playback plugin
#       
#       Copyright 2008 Charlotte Curtis <c.f.curtis@gmail.com>
#       
#       This program is free software; you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation; either version 2 of the License, or
#       (at your option) any later version.
#       
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#       
#       You should have received a copy of the GNU General Public License
#       along with this program; if not, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.

import gtk
import gtk.glade
import gobject
import gconf

class InTheMoodPrefsDialog(object):
	def __init__(self, glade_file, itm_instance):
		# remember the plugin instance
		self.itm_instance = itm_instance
		
		# Get the widgets from the glade file
		self.gladexml = gtk.glade.XML(glade_file)
		self.dialog = self.gladexml.get_widget('itmPrefs')
		self.btn_evolve = self.gladexml.get_widget('btn_evolve')
		self.btn_popup = self.gladexml.get_widget('btn_popup')
		self.lbl_status = self.gladexml.get_widget('lbl_status')
		self.btn_scan_new = self.gladexml.get_widget('btn_scan_new')
		self.btn_scan_now = self.gladexml.get_widget('btn_scan_now')
		
		# connect actions
		self.dialog.connect('response', self.dialog_response)
		
		# set up gconf and check parameters
		self.gconfclient = gconf.client_get_default()
		self.gconfpath = '/apps/rhythmbox/plugins/inthemood/'
		self.scan_complete = self.gconfclient.get_bool(self.gconfpath + 'scan_complete')
		self.do_popup = self.gconfclient.get_bool(self.gconfpath + 'do_popup')
		self.scan_on_add = self.gconfclient.get_bool(self.gconfpath + 'scan_on_add')
		self.evolve = self.gconfclient.get_bool(self.gconfpath + 'evolve')
		
		# update preferences dialog with current values
		if self.scan_complete:
			self.lbl_status.set_text("Library analysis is complete")
		self.btn_popup.set_active(self.do_popup)
		self.btn_evolve.set_active(self.evolve)
	
	def dialog_response(self, dialog, response):
		if response == gtk.RESPONSE_OK:
			# update gconf values
			self.gconfclient.set_bool(self.gconfpath + 'do_popup', self.btn_popup.get_active())
			self.gconfclient.set_bool(self.gconfpath + 'evolve', self.btn_evolve.get_active())
			self.gconfclient.set_bool(self.gconfpath + 'scan_on_add', self.btn_scan_new.get_active())
			self.itm_instance.update_prefs()
		elif response == 42:
			# begin analysis
			self.itm_instance.scan_paused = False
			self.itm_instance.scan_library()
		elif response == gtk.RESPONSE_CANCEL or response == gtk.RESPONSE_NONE:
			print 'Cancelling'
		else:
			# This should never happen
			print "Unknown response type " + str(response)
		self.dialog.hide()
	
	def get_dialog(self):
		return self.dialog

